package com.fyzk.activity.zhifu;

import android.os.Bundle;
import android.os.Handler;
import android.widget.TextView;

import com.fyzk.activity.app.App;
import com.fyzk.activity.app.AppToast;
import com.fyzk.activity.lottery.jc.football.JCInfo;
import com.fyzk.activity.lottery.jc.football.guoguan.JC_GuoGuanDialog;
import com.fyzk.adapter.JCBaseAdapter;
import com.fyzk.utils.IntentParamUtils;
import com.tyjc.lottery.R;

import java.util.ArrayList;

/**
 * 竞彩支付的基类
 *
 * @author fxs
 * @time 2016年1月9日
 */
public abstract class JCBasePayActivity extends BetBaseActivity {

    public static final int ZF_WHAT1 = 1;

    protected int wanFa = 1;

    public final String RESULT_MOREN = "";
    public TextView tv_guoGuanStyle;
    public static ArrayList<JCInfo> infos = new ArrayList<>();
    protected JCBaseAdapter adapter;

    // 其它
    public static boolean isZhifu = false;
    protected final int oneAmount = 200;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        isZhifu = true;
    }

    @Override
    protected void onDestroy() {
        isZhifu = false;
        super.onDestroy();
    }

    @Override
    public void onBackPressed() {
        finish();//支付页退出不做任何操作
    }

    @Override
    public int getZhushu() {
        return zhushu;
    }

    @Override
    public boolean isJC() {
        return true;
    }


    protected Handler handler = new Handler() {
        public void handleMessage(android.os.Message msg) {
            switch (msg.what) {
                case ZF_WHAT1:
                    int count = msg.arg1;
                    int zhushu_adpter = (Integer) msg.obj;
//                    if (getZhushu() != zhushu_adpter) {
                    zhushu = zhushu_adpter;
                    setBtmView();
//                    }
                    wanFa = msg.arg2;
                    if (changCi != count) {
                        changCi = count;
                        initGuoGuanView();
                    }
                    break;
                case IntentParamUtils.CHANGE_GUOGUAN:
                    JC_GuoGuanDialog.result = getString(R.string.guoguan_hint);
                    tv_guoGuanStyle.setText(JC_GuoGuanDialog.result);
                    adapter.jiSuanZhuShu();
                    break;
                default:
                    break;
            }
        }
    };

    /**
     * 重置过关显示控件数据
     */
    public void initGuoGuanView() {

    }

    public boolean recommendeble() {
        if (getMoney() > maxBounusPrize) {
            AppToast.getToast().show("晒单失败，理论奖金需大于投注彩金");
            handler.sendEmptyMessage(IntentParamUtils.CHANGE_GUOGUAN);
            return false;
        } else {
            return true;
        }
    }

    @Override
    public void lingAlert() {
        if (JC_GuoGuanDialog.result.equals(getString(R.string.guoguan_hint))) {
            AppToast.getToast().show(R.string.guoguan_hint);
        } else {
            AppToast.getToast().show(R.string.guoguan_bisai);
        }

    }

    @Override
    protected boolean hemaiAble() {
        if ((isDanguan) || getZhushu() < 10000) {
            return true;
        }
        AppToast.getToast().show("过关投注单倍最大投注彩金不能超过20000米！");
        return false;
    }

    /**
     * 获取投注注码
     */
    protected abstract String getContent();

    @Override
    public String getBetCode() {
        if (null != tv_guoGuanStyle) {
            JC_GuoGuanDialog.result = tv_guoGuanStyle.getText().toString();
        }
        return getContent();
    }

    @Override
    public boolean isShowStartBask() {
        return !App.isBaskOrder;
    }

    /**
     * 获取期号
     *
     * @return
     */
    public String getPhase() {
        return getIntent().getStringExtra(IntentParamUtils.ZC_PHASE);
    }


}
